<template>
  <div>
     <!-- 底部部分 -->
     <footer class="footer">
      <span class="todo-count"><strong>{{leftCount}}</strong>剩余</span>
      <ul class="filters" @click="$emit('changeType',type)">
        <li>
          <a :class="{selected :type === 'all'}" 
          @click.prevent="type ='all'"
          href="#/">全部</a>
        </li>
        <li>
          <a :class="{selected :type === 'active'}" 
          @click.prevent="type ='active'" 
          href="#/active">进行中</a>
        </li>
        <li>
          <a :class="{selected :type === 'completed'}" 
          @click.prevent="type ='completed'" 
          href="#/completed">已完成</a>
        </li>
      </ul>
      <!-- 当没完成的任务数量不等原数组的长度 清楚已完成显示 -->
      <button class="clear-completed" @click="hClear" v-show="leftCount !== list.length">清除已完成</button>
    </footer>
  </div>
</template>

<script>
export default {
  name: 'TodoFooter',
  props: {
    list : {
      type:Array,
      required : true
    }
  },
  data() {
    return {
      type :'all'
    };
  },

  methods: {
    hClear() {
      this.$emit('cDone')
    }
  },
  computed : {
    leftCount() {
      // return this.list.length 
      return (this.list.filter(item => !item.isDone)).length
    },
    clearDone() {
      // some 有一个为true 就返回true
      return this.list.some(item => item.isDone )
    }
  }
};
</script>

<style lang="scss" scoped>

</style>